<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/27
 * Time: 10:19
 */

namespace App\Game\Traits;

use Illuminate\Support\Facades\DB;

trait VgTrait
{
    public function vgRequest($params)
    {
        $verifyCode = $this->getVerifyCode($params);
        $params = array_merge($params, ['verifyCode' => $verifyCode]);
        $result = $this->request('GET', $this->gameUrl, $params);
        return $this->xmlToArray($result);
    }

    public function getVerifyCode($params)
    {
        $verifyCodeStr = '';

        foreach ($params as $key => $value) {
            $verifyCodeStr .= $value;
        }
        $verifyCodeStr .= $this->privateKey;

        return strtoupper(md5($verifyCodeStr));
    }

    public function getMaxId()
    {
        $maxId = DB::table('log_player_bet_flow')
            ->where('main_game_plat_code', $this->platName)
            ->select(DB::raw("max(game_flow_code + 0) game_flow_code"))->first();
        $maxId = $maxId->game_flow_code ? $maxId->game_flow_code : 0;

        return $maxId;
    }

    public function vgRecordRequest($params)
    {
        $verifyCode = $this->getVerifyCode($params);
        $params = array_merge($params, ['verifyCode' => $verifyCode]);
        $result = $this->request('GET', $this->gameData, $params);
        return json_decode($result, true);
    }


}